package operations;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Borrow implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");
        System.out.println("请输入借阅的图书的名字：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.nextLine();
        int index=-1;
        int curSize=bookList.getUsedSize();
        for (int i = 0; i < curSize; i++) {
            Book book=bookList.getPos(i);
            if(name.equals(book.getName())){
                if(book.isState()){
                    System.out.println("已被借出");

                }else {
                    book.setState(true);
                    System.out.println("借阅成功");
                }
                return;
            }
        }

            System.out.println("没有要借阅的书");


    }
}
